home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / comm / bbs / cit_src_AD08.lha / cim.c < prev    next >
C/C++ Source or Header  |  1997-07-27  |  6KB  |  188 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <dos.h>
  6. #include <dos/dos.h>
  7. #include <clib/dos_protos.h>
  8. #include <pragmas/dos_pragmas.h>
  9. #include "sysdep.h"
  10. extern struct DosLibrary *DOSBase;
  11. /**
  12.   Citadel Internet Mailer Version 1.00
  13.  
  14.   Input:  parameter filename
  15.   Output:
  16.  This tool is designed to work with AirMail Version 3  It will queue
  17.  a mail into the directory you specify(it should be the out box for AirMail).
  18.  
  19.  Since AirMail has no control over the file for the new mail, this tool
  20.  will create the new mail with a header that looks like this:
  21.  
  22. [AIRMAIL3]                      --> Mail keyword.
  23. To: toysoft@connect.ab.ca,      --> Must come before the TO: address/s.
  24. From: toysoft@connect.ab.ca     --> Automatically displayed.                            --> Must come before the DATE.
  25. Date: Nov 24 1995 11:11:09 PM   --> Automatically displayed.
  26. Subject: Air Mail is great!     --> Automatically displayed or entered.
  27. [FILES]                         --> Must come before an attached FILE.
  28. X-Mailer: Citadel Internet Mailer V 6J20
  29.  <blank line>
  30. 1. The maximum number of characters per line in the header in 60 characters.
  31. 2. You can have as many lines in the TO: and [FILES] block.
  32. 3. A ', ' comma and space separates each email address or file.
  33. 4. A ', ' comma and space terminates each line in the [TO] and [FILES] block
  34. 5. There must be a blank line between the last line in the header block
  35.    and your message.
  36.  
  37. **/
  38. int month_number(char *name);
  39. int main(int argc, char **argv);
  40.  
  41. #define IN_PARAMS  (7)
  42.  
  43. char  *param[IN_PARAMS];
  44.  
  45.  
  46. int month_number(char *name)
  47.   {
  48.   switch (name[0])
  49.     {
  50.     case 'A':  /* april or august */
  51.       return ( name[1] == 'U' ? 8 : 4 );
  52.     case 'D':  /* december */
  53.       return 12;
  54.     case 'F':  /* febuary */
  55.       return 2;
  56.     case 'J':  /* january, june or july */
  57.       return ( name[1] == 'A' ? 1 : ( name[2] == 'L' ? 7 : 6 ) );
  58.     case 'M':  /* may or march */
  59.       return ( name[2] == 'R' ? 3 : 5 );
  60.     case 'N':  /* november */
  61.       return 11;
  62.     case 'O':  /* october */
  63.       return 10;
  64.     };
  65.   return 9;  /* september */
  66.   }
  67.  
  68. int main(int argc, char **argv)
  69.   {
  70.   time_t  timeval;
  71.   struct tm *tp;
  72.   long t;
  73.   long count;
  74.   int found;  /* flags */
  75.   int flag;
  76.   char buffer[128];
  77.   char line[120];
  78.   char times[26];
  79.   char filename[20];
  80.   FILE *mail_file;
  81.   FILE *mail_out;
  82.   FILE *p_file;
  83.   char *ptr;
  84.   int i;
  85.   printf("Citadel Internet Mailer %s\n", VERSION_NAME);
  86.   if( argc != 2 )
  87.     {
  88.     printf("Usage: CIM <Parameter File> \n");
  89.     return 100;
  90.     };
  91.   /**
  92.     Read the parameter file and validate that we have access to
  93.     the mail packet file plus it is not zero length.
  94.   **/
  95.   if( ( p_file  = fopen(argv[1],"r") ) == NULL )
  96.     {
  97.     fprintf(stderr,"Error: cannot open parameter file(%s)\n",argv[1]);
  98.     exit(100);
  99.     };
  100.     /**
  101.       Read parameters
  102.     **/
  103.     for(i=0; i<IN_PARAMS; i++)
  104.       {
  105.       if( fgets(line, sizeof(line), p_file) == NULL )
  106.         {
  107.         fprintf(stderr,"Error: EOF while reading parameter file line %d\n",i);
  108.         fclose(p_file);
  109.         exit(100);
  110.         };
  111.       if( ( ptr = strchr(line,'\n') ) != NULL ) *ptr = '\0';
  112.       param[i] = strdup(line);
  113.       };
  114.   /**
  115.     Check to see that we have read access to the Mail file before we
  116.     attempt to create the mail message.
  117.   **/
  118.   if( access(param[5],R_OK) == -1 )
  119.     {
  120.     printf("Error: Unable to open mail file(%s), aborting\n", param[5]);
  121.     exit(100);
  122.     };
  123.   /**
  124.     Open the queued mail file, first we must figure out the file
  125.     name.  The filename is of the form YYYYMMDD<count>.AM, count starts
  126.     at 1 and increments until a filename is not found, then we create that
  127.     file.
  128.   **/
  129.   time(&timeval);
  130.   tp = localtime(&timeval);
  131.   sprintf(times,"%s",asctime(tp) );
  132.   for(t=0; t<4; t++) filename[0+t] = times[20+t]; /* copy year */
  133.   filename[4] = '.';
  134.   sprintf(&filename[5],"%02.2d",month_number(×[4])); /* month */
  135.   filename[7] = '.';
  136.   for(t=0; t<2; t++) filename[8+t] = times[ 8+t]; /* day of the month */
  137.   filename[10] = '\0';
  138.   /*
  139.    count starts at 1, we look for an empty slot number and add the file
  140.    there.
  141.   */
  142.   t = strlen(param[6])-1;
  143.   flag = FALSE;
  144.   if( param[6][t] == '/' || param[6][t] == ':')flag=TRUE;
  145.   count = 0;
  146.   found = TRUE;
  147.   while ( found )
  148.     {
  149.     count++;
  150.     if( flag )
  151.       {
  152.       sprintf( buffer, "%s%s.%03.3d.AM", param[6], filename, count);
  153.       }
  154.     else sprintf( buffer, "%s/%s.%03.3d.AM", param[6], filename, count);
  155.     if( access(buffer,F_OK) == -1 ) break;
  156.     };
  157.   /*
  158.    found an empty slot, create the file
  159.   */
  160.   if( (mail_out = fopen(buffer,"w")) == NULL )
  161.     {
  162.     printf("Error: Cannot create mail file(%s)\n",buffer);
  163.     exit (100);
  164.     };
  165.   fprintf( mail_out, "[AIRMAIL3]\n");
  166.   fprintf( mail_out, "To: %s,\n",      param[0]);
  167.   fprintf( mail_out, "From: %s\n",     param[1]);
  168.   fprintf( mail_out, "Reply-To: %s\n", param[2]);
  169.   fprintf( mail_out, "Date: %s\n",      ×[4]);
  170.   fprintf( mail_out, "Subject: %s\n",  param[3]);
  171.   fprintf( mail_out, "Organization: %s\n",param[4]);
  172.   fprintf( mail_out, "[FILES]\n");
  173.   fprintf( mail_out, "X-Mailer: Citadel Internet Mailer (6J20)\n\n");
  174.   /* copy the mail file */
  175.   if( (mail_file = fopen(param[5],"r")) == NULL )
  176.     {
  177.     fclose(mail_out);
  178.     printf("Error: cannot open mail to send file(%s)\n",argv[1]);
  179.     exit(100);
  180.     };
  181.   while( fgets(line,sizeof(line), mail_file) ) fputs(line, mail_out);
  182.   fprintf(mail_out,"\n");
  183.   fclose(mail_out);
  184.   fclose(mail_file);
  185.   SetComment( buffer, "QUEUED");
  186.   exit(0);
  187.   }
  188.